﻿namespace SimpleWebServices.Web
{
    using System;
    using System.Web;

    public static class HttpContextFactory
    {
        [ThreadStatic]
        private static HttpContextBase _mock;

        public static HttpContextBase Current
        {
            get
            {
                HttpContextBase value = null;

                if (null != _mock)
                {
                    value = _mock;
                }
                else if (null != HttpContext.Current)
                {
                    value = new HttpContextWrapper(HttpContext.Current);
                }

                return value;
            }
        } 

        public static HttpContextBase Mock
        {
            get
            {
                return _mock;
            }

            set
            {
                _mock = value;
            }
        }

        public static void Reset()
        {
            HttpContextFactory.Mock = null;
        }
    }
}